﻿namespace Methods
{
    using System;

    public class Methods
    {
        public static double CalcTriangleArea(double a, double b, double c)
        {
            if (a <= 0 || b <= 0 || c <= 0)
            {
                throw new ArgumentOutOfRangeException("Sides should be positive!");
            }
            else if (a + b <= c || a + c <= b || b + c <= a)
            {
                throw new ArgumentException("These sides does not form a trinagle!");
            }

            double s = (a + b + c) / 2;
            double area = Math.Sqrt(s * (s - a) * (s - b) * (s - c));

            return area;
        }

        public static string DigitToWord(int digit)
        {
            switch (digit)
            {
                case 0:
                    return "zero";
                case 1:
                    return "one";
                case 2:
                    return "two";
                case 3:
                    return "three";
                case 4:
                    return "four";
                case 5:
                    return "five";
                case 6:
                    return "six";
                case 7:
                    return "seven";
                case 8:
                    return "eight";
                case 9:
                    return "nine";
            }

            throw new ArgumentOutOfRangeException("Invalid digit!");
        }

        public static int FindMax(params int[] elements)
        {
            if (elements == null)
            {
                throw new ArgumentNullException("Array must not be null!");
            }
            else if (elements.Length == 0)
            {
                throw new ArgumentOutOfRangeException("Array must have at least 1 element!");
            }

            int maxNumber = elements[0];
            for (int i = 1; i < elements.Length; i++)
            {
                if (elements[i] > maxNumber)
                {
                    maxNumber = elements[i];
                }
            }

            return maxNumber;
        }

        public static void PrintAsNumber(object number, NumberPrintFormat format)
        {
            decimal decimalNumber;
            if (!decimal.TryParse(number.ToString(), out decimalNumber))
            {
                throw new FormatException("Object must be valid number!");
            }

            string numberPattern;
            if (format == NumberPrintFormat.Float)
            {
                numberPattern = "{0:f2}";
            }
            else if (format == NumberPrintFormat.Percent)
            {
                numberPattern = "{0:p0}";
            }
            else if (format == NumberPrintFormat.Right)
            {
                numberPattern = "{0,8}";
            }
            else
            {
                throw new ArgumentException("Invalid format type! Only NumberPrintFormat enumeration elements are allowed.");
            }

            Console.WriteLine(numberPattern, decimalNumber);
        }

        public static double CalcDistance(Point firstPoint, Point secondPoint)
        {
            return firstPoint.CalcDistance(secondPoint);
        }

        public static bool InHorizontalLine(Point firstPoint, Point secondPoint)
        {
            return firstPoint.InHorizontalLineWith(secondPoint);
        }

        public static bool InVerticalLine(Point firstPoint, Point secondPoint)
        {
            return firstPoint.InVerticalLineWith(secondPoint);
        }

        public static void Main()
        {
            Console.WriteLine(CalcTriangleArea(3, 4, 5));

            Console.WriteLine(DigitToWord(5));

            Console.WriteLine(FindMax(5, -1, 3, 2, 14, 2, 3));

            PrintAsNumber(1.3, NumberPrintFormat.Float);
            PrintAsNumber(0.75, NumberPrintFormat.Percent);
            PrintAsNumber(2.30, NumberPrintFormat.Right);

            Point firstPoint = new Point(3, -1);
            Point secondPoint = new Point(3, 2.5);
            Console.WriteLine(CalcDistance(firstPoint, secondPoint));
            Console.WriteLine("Horizontal? " + InHorizontalLine(firstPoint, secondPoint));
            Console.WriteLine("Vertical? " + InVerticalLine(firstPoint, secondPoint));

            Student peter = new Student()
            {
                FirstName = "Peter",
                LastName = "Ivanov",
                BirthDate = new DateTime(1992, 03, 17),
                LivingCity = "Sofia"
            };

            Student stella = new Student()
            {
                FirstName = "Stella",
                LastName = "Markova",
                BirthDate = new DateTime(1993, 11, 03),
                LivingCity = "Vidin",
                About = "gamer, high results"
            };

            Console.WriteLine("{0} older than {1} -> {2}", peter.FirstName, stella.FirstName, peter.IsOlderThan(stella));
        }
    }
}